﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IBLL;
using Dtos;
using DAL;
using IDAL;

namespace BLL
{
    public class GradesBll : IGradesBll
    {
        public IGradesDal _gradesDal;
        public GradesBll(IGradesDal gradesDal)
        {
            _gradesDal = gradesDal;
        }
        public async Task<int> AddGradesAsync(string title)
        {
            return await _gradesDal.AddAsync(new Model.Grades
            {
                title = title
            });
        }
        public async Task<int> DeleteGradesAsync(Guid id)
        {
            var data = await _gradesDal.GetIdAll(id);
            if (data != null)
                return await _gradesDal.DeleteAsync(data);
            return 0;
        }
        public async Task<int> EditGradesAsync(Guid id,string title)
            {
            var data = await _gradesDal.GetIdAll(id);
            if(data == null)
                return 0;
            data.title=title;
            data.UpdateTime=DateTime.Now;
            return await _gradesDal.UpdateAsync(data);
            }
        public async Task<List<GradesDtos>> GetAllGrades() 
        {
            var data = await _gradesDal.GetAll();
            return data.Select(m => new GradesDtos
            {
                Id = m.Id,
                Title = m.title,
                UpdateTime = m.UpdateTime,
            }).ToList();
        }
        public Task<GradesDtos> GetGradesByIdAsync(Guid id)
        {
            throw new NotImplementedException();
        }
        public Task<bool> IsExistsAsync(string title)
        {
            throw new NotImplementedException();
        }
    }
}
